#include "Task_events.h"
#include "appdata/app_data.h"
#include "keyboard.h"
#include "png/png.h"
#include "lvgl.h"
#include "lv_port_indev.h"
extern lv_indev_t *indev_keypad;
extern lv_indev_t *indev_encoder;
extern lv_group_t *foc_group;
extern lv_group_t *kb_group;

lv_obj_t *SKY_PAGE;

bool SKY_running = 0; // 判断LVGL任务是否运行
void Dynamic_Island_DL(void *pvParameters)
{
    lv_obj_t *png = lv_img_create(lv_scr_act());
    lv_img_set_src(png, &ui_img_dial_png);
    lv_obj_set_width(png, 240);
    lv_obj_set_height(png, 240);
    lv_obj_set_align(png, LV_ALIGN_CENTER);
    lv_obj_set_style_radius(png, 120, LV_PART_MAIN | LV_STATE_DEFAULT);
    while (dial_or_lvgl == 0)
        vTaskDelay(1);
    lv_obj_del(png);
    vTaskDelete(NULL);
}

void Dynamic_Island(void *pvParameters)
{
    //vTaskSuspendAll(); // 挂起任务调度器，防止其他任务干扰
    SKY_running = 1;
    lv_obj_t *mbox = lv_msgbox_create(lv_scr_act(), "Smart_KB32", (char *)pvParameters, NULL, NULL);
    lv_obj_set_width(mbox, 180);
    lv_obj_set_height(mbox, 70);
    lv_obj_align(mbox, LV_ALIGN_CENTER, 0, -30);
    lv_obj_set_style_radius(mbox, 30, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(mbox, 220, LV_PART_MAIN | LV_STATE_DEFAULT);
    // lv_group_add_obj(foc_group, mbox);
    uint32_t millis_time = millis();
    while (millis() - millis_time < 2000 and SKY_running)
        ;
    lv_obj_del(mbox);
    // Serial.print(F("Task Free Memory: "));           // 任务剩余空间
    // Serial.print(uxTaskGetStackHighWaterMark(NULL)); // 返回值即是当前任务所剩栈空间的最小值
    SKY_running = 0;
   // xTaskResumeAll(); // 取消挂起任务调度器
    vTaskDelete(NULL);
}

void computer(void *pvParameters)
{
    SKY_running = 1;
    Serial.println("识别到指纹");
    bleKeyboard.press(KEY_LEFT_SHIFT); // 电脑休眠
    bleKeyboard.releaseAll();
    lv_obj_t *mbox = lv_msgbox_create(lv_scr_act(), "Smart_KB32", "turn on the computer ", NULL, NULL);
    lv_obj_set_width(mbox, 200);
    lv_obj_set_height(mbox, 80);
    lv_obj_align(mbox, LV_ALIGN_CENTER, 0, -30);
    uint32_t millis_time = millis();
    while (millis() - millis_time < 2000 and SKY_running)
        vTaskDelay(1);
    bleKeyboard.println(8977);
    lv_obj_del(mbox);
    // Serial.print(F("Task Free Memory: "));           // 任务剩余空间
    // Serial.print(uxTaskGetStackHighWaterMark(NULL)); // 返回值即是当前任务所剩栈空间的最小值
    SKY_running = 0;
    vTaskDelete(NULL);
}


